<?php

namespace Database\Seeders;

use App\Models\Actor;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Storage;

class ActorSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $actors = [
            [
                'title' => '言和',
                'picture' => 'https://api.madouapi.com/actor/1.png',
            ],
            [
                'title' => '嫣汐',
                'picture' => 'https://api.madouapi.com/actor/2.png',
            ],
            [
                'title' => '乐正绫',
                'picture' => 'https://api.madouapi.com/actor/3.png',
            ],
            [
                'title' => '东方栀子',
                'picture' => 'https://api.madouapi.com/actor/4.png',
            ],
            [
                'title' => '洛天依',
                'picture' => 'https://api.madouapi.com/actor/5.png',
            ],
            [
                'title' => '初音未来',
                'picture' => 'https://api.madouapi.com/actor/6.png',
            ],
        ];

        foreach ($actors as $actor) {
            $path = 'actors/'.pathinfo($actor['picture'], PATHINFO_BASENAME);

            if (! Storage::exists($path)) {
                $str = file_get_contents($actor['picture']);
                Storage::put($path, $str);
            }

            $actor['picture'] = $path;

            Actor::query()->create($actor);
        }
    }
}
